package com.ccs.blockchain.demo;

import java.util.*;

import com.alibaba.fastjson.JSON;
import com.ccs.blockchain.common.HttpClient;
import com.ccs.blockchain.eneity.ParamObj;
import com.ccs.blockchain.eneity.ResponseObj;
import com.ccs.blockchain.eneity.account.AccountFeedType;
import com.ccs.blockchain.eneity.account.AccountParamBody;
import com.ccs.blockchain.eneity.adgroup.AdgroupFeedType;
import com.ccs.blockchain.eneity.adgroup.AdgroupParamBody;
import com.ccs.blockchain.eneity.bulk.BulkParamBody;
import com.ccs.blockchain.eneity.campaign.CampaignFeedType;
import com.ccs.blockchain.eneity.campaign.CampaignParamBody;
import com.ccs.blockchain.eneity.creative.CreativeFeedType;
import com.ccs.blockchain.eneity.creative.CreativeParamBody;
import com.ccs.blockchain.eneity.creative.Material;
import com.ccs.blockchain.eneity.report.ReportParamBody;

public class BaiduFeedTest {

    public static void main(String[] args) throws Exception {
    	ParamObj param = new ParamObj();
    	param.setAccessKey("49e8f9401dc04987913f1ba00ef06cdc");
    	param.setSecretKey("a5bfb4b455794973b1abd8fd36f7ef02");
    	param.setBceUser("4724ed9814664b199c279c26948e1c1c");
    	param.setOpUsername("尚德机构2016新");
    	param.setOpPassword("17170shangDJ");
    	param.setTgSubname("尚佳64");
        param.setStartDays(16);
        param.setEndDays(0);


//    	AccountParamBody accountBody = new AccountParamBody();
//    	accountBody.setAccountFeedFields(Arrays.asList(new String[]{"userId", "balance", "uaStatus"}));
//    	param.setAccountBody(accountBody);
//
//    	CampaignParamBody campaignBody = new CampaignParamBody();
//    	campaignBody.setCampaignFeedIds(new ArrayList<String>());
//    	campaignBody.setCampaignFeedFields(Arrays.asList(new String[]{"campaignFeedId", "campaignFeedName"}));
//    	param.setCampaignBody(campaignBody);
//
//    	AdgroupParamBody adgroupBody = new AdgroupParamBody();
//    	adgroupBody.setAdgroupFeedFields(Arrays.asList(new String[]{"adgroupFeedId", "campaignFeedId", "adgroupFeedName", "pause", "status"}));
//    	adgroupBody.setIdType(1);
//    	adgroupBody.setIds(Arrays.asList(new Long[]{74905479L}));
//    	param.setAdgroupBody(adgroupBody);
//
//
//    	CreativeParamBody creativeBody = new CreativeParamBody();
//    	creativeBody.setCreativeFeedFields(Arrays.asList(new String[]{"creativeFeedId", "adgroupFeedId", "creativeFeedName", "pause", "status", "materialstyle", "material"}));
//    	creativeBody.setIdType(2);
//    	creativeBody.setIds(Arrays.asList(new Long[]{2976182379L}));
//    	param.setCreativeBody(creativeBody);
//
//
//    	BulkParamBody bulkBody = new BulkParamBody();
//    	bulkBody.setCampaignIds(Arrays.asList(new Long[]{74905479L}));
//    	bulkBody.setFormat(0);
//    	bulkBody.setFeedCampaignFields(Arrays.asList(new String[]{"campaignFeedId"}));
//    	param.setBulkBody(bulkBody);

    	Map<String, String> paramMap = new HashMap<String, String>();
    	paramMap.put("param", JSON.toJSONString(param));
    	
//    	account(paramMap);
//    	campaign(paramMap);
//    	adgroup(paramMap);
//    	creative(paramMap);
    	report(paramMap);
    	
//    	System.out.println("账户：|||||" + HttpClient.get("http://180.76.50.6:8080/baidu/feed/account/getAccountFeed", paramMap, new HashMap<String, String>()));
//    	
//    	System.out.println("计划：|||||" + HttpClient.get("http://180.76.50.6:8080/baidu/feed/campaign/getCampaignFeed", paramMap, new HashMap<String, String>()));
//    	
//    	System.out.println("单元：|||||" + HttpClient.get("http://180.76.50.6:8080/baidu/feed/adgroup/getAdgroupFeed", paramMap, new HashMap<String, String>()));
//    
//    	System.out.println("创意：|||||" + HttpClient.get("http://180.76.50.6:8080/baidu/feed/creative/getCreativeFeed", paramMap, new HashMap<String, String>()));
//    	
//    	System.out.println("批量：|||||" + HttpClient.get("http://180.76.50.6:8080/baidu/feed/bulk/getAllFeedObjects", paramMap, new HashMap<String, String>()));
    }
    
    private static void account(Map<String, String> paramMap) {
    	String accountStr = HttpClient.get("http://180.76.50.6:8080/baidu/feed/account/getAccountFeed", paramMap, new HashMap<String, String>());
    	List<AccountFeedType> accountList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(accountStr, ResponseObj.class).getBody().getData()), AccountFeedType.class);
    	System.out.println("账户Str：" + accountStr);
    	System.out.println("账户Size" + accountList.size());
    }
    
    private static void campaign(Map<String, String> paramMap) {
    	String campaignStr = HttpClient.get("http://180.76.50.6:8080/baidu/feed/campaign/getCampaignFeed", paramMap, new HashMap<String, String>());
    	List<CampaignFeedType> campaignList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(campaignStr, ResponseObj.class).getBody().getData()), CampaignFeedType.class);
    	System.out.println("计划Str：" + campaignStr);
    	System.out.println("计划Size" + campaignList.size());
    }
    private static void report(Map<String, String> paramMap) {
//    	String reportStr = HttpClient.get("http://localhost:8080/baidu/feed/report/getRealTimeFeedData", paramMap, new HashMap<String, String>());
    	String reportStr = HttpClient.get("http://180.76.50.6:8081/baidu/feed/report/getRealTimeFeedData", paramMap, new HashMap<String, String>());
		System.out.println(reportStr);
    }
    
    private static void adgroup(Map<String, String> paramMap) {
    	String adgroupStr = HttpClient.get("http://180.76.50.6:8080/baidu/feed/adgroup/getAdgroupFeed", paramMap, new HashMap<String, String>());
    	List<AdgroupFeedType> adgroupList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(adgroupStr, ResponseObj.class).getBody().getData()), AdgroupFeedType.class);
    	System.out.println("单元Str：" + adgroupStr);
    	System.out.println("单元Size" + adgroupList.size());
    }
    
    private static void creative(Map<String, String> paramMap) {
    	String creativeStr = HttpClient.get("http://180.76.50.6:8080/baidu/feed/creative/getCreativeFeed", paramMap, new HashMap<String, String>());
    	List<CreativeFeedType> creativeList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(creativeStr, ResponseObj.class).getBody().getData()), CreativeFeedType.class);
    	System.out.println("创意Str：" + creativeStr);
    	System.out.println("创意Size" + creativeList.size());
    	if (creativeList != null && !creativeList.isEmpty()) {
    		String materialStr = creativeList.get(0).getMaterial();
    		if (materialStr != null) {
    			Material material = JSON.parseObject(materialStr, Material.class);
        		System.out.println("image :" + material.getPictures().get(0).getImage());
    		}
    	}
    }
	private static Date getStartTime() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DAY_OF_MONTH, -30);
		cal.set(Calendar.HOUR,0);
		cal.set(Calendar.MINUTE,0);
		cal.set(Calendar.SECOND,0);
		return cal.getTime();
	}
	private static Date getEndTime() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DAY_OF_MONTH, 0);
		cal.set(Calendar.HOUR_OF_DAY,23);
		cal.set(Calendar.MINUTE,59);
		cal.set(Calendar.SECOND,59);
		return cal.getTime();
	}
}
